package com.gxa.controller.asset;
import java.util.Date;

import com.gxa.common.utils.R;
import com.gxa.entity.asset.AuthApply;
import com.gxa.entity.discrepancy.Device;
import com.gxa.service.asset.AuthApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

import static com.gxa.common.utils.R.error;
import static com.gxa.common.utils.R.ok;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yjl
 * @since 2022-10-12 11:37:50
 */
@Api(tags = "资产授权申请")
@RestController
@RequestMapping("/auth-apply")
public class AuthApplyController {

    @Autowired
    private AuthApplyService authApplyService;


    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("资产授权申请列表接口")
    @GetMapping("/list")
    public R queryAll(){
        List<AuthApply> list = authApplyService.list();
        return ok("successs").put("data",list);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("新增资产授权申请接口")
    @PostMapping("/add")
    public R add(@RequestBody AuthApply device){
        boolean save = authApplyService.save(device);
        if (save){
            return ok("添加成功");
        }
        return error();
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("删除资产授权申请接口")
    @DeleteMapping("/del/{id}")
    public R del(@PathVariable("id") Integer id){
        boolean removeById = authApplyService.removeById(id);
        if(removeById){
            return ok("删除成功");
        }
        return ok("del error");
    }
    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("根据id查询资产授权申请接口")
    @GetMapping("/queryById/{id}")
    public R queryById(@PathVariable("id") Integer id){
        AuthApply byId = authApplyService.getById(id);
        if(byId != null){
            return ok("查询成功");
        }
        return error("query error");
    }
    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("编辑资产授权申请接口")
    @PutMapping("/edit")
    public R edit(@RequestBody AuthApply device){
        if(authApplyService.updateById(device)){
            return ok("更新成功");
        }
        return ok("edit error");
    }
}
